package net.dotool.page;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import net.dotool.StringTools;

/**
 * @author 李岩飞
 * @email eliyanfei@126.com 2017年12月21日 上午9:34:04
 * 
 */
public class PageModel {
	private long count;// 总数
	private List<?> data;// 数据
	private int page = 1;// 第几页
	private int limit = 10;// 条码
	private int code = 0;// 返回状态吗
	private String msg = "";// 返回消息内容
	private String search;// 搜索内容
	private boolean excel;// 导出数据
	private String excelType;// 文件类型
	private String orderBy;// 字段
	private String orderSort;// asc
	private boolean loadcol;// 从后台加载cols
	private Collection<?> cols = new ArrayList<>();// 字段列
	private Map<String, String> colsMap = new LinkedHashMap<String, String>();
	private String fields;
	private boolean reload = false;

	public PageModel() {
	}

	public void setExcelType(String excelType) {
		this.excelType = excelType;
	}

	public String getExcelType() {
		return excelType;
	}

	public void setReload(boolean reload) {
		this.reload = reload;
	}

	public boolean isReload() {
		return reload;
	}

	public Map<String, String> getColsMap() {
		return colsMap;
	}

	public void setFields(String fields) {
		this.fields = fields;
		if (StringTools.isNotEmpty(fields)) {
			String[] arr1 = fields.split(",");
			for (String str : arr1) {
				if (StringTools.isNotEmpty(str)) {
					String[] arr2 = str.split(";");
					if (arr2.length == 2) {
						colsMap.put(arr2[0], arr2[1]);
					}
				}
			}
		}
	}

	public String getFields() {
		return fields;
	}

	public void setCols(Collection<?> cols) {
		this.cols = cols;
	}

	public Collection<?> getCols() {
		return cols;
	}

	public void setLoadcol(boolean loadcol) {
		this.loadcol = loadcol;
	}

	public boolean isLoadcol() {
		return loadcol;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public void setOrderSort(String orderSort) {
		this.orderSort = orderSort;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public String getOrderSort() {
		return orderSort;
	}

	public boolean isExcel() {
		return excel;
	}

	public void setExcel(boolean excel) {
		this.excel = excel;
	}

	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public int getPage() {
		return page;
	}

	public int getStart() {
		return (page - 1) * limit;
	}

	public int getEnd() {
		return (page) * limit;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public void setData(List<?> data) {
		this.data = data;
		this.code = 0;
	}

	public List<?> getData() {
		return data;
	}

	public void setCount(long count) {
		this.count = count;
	}

	public long getCount() {
		return count;
	}

	public PageModel toPageModel(List list) {
		this.setData(list);
		return this;
	}

	public int getNo(int idx) {
		return (page - 1) * limit + idx;
	}
}
